79134c
@@ -22,6 +22,7 @@
 import org.apache.hadoop.hive.service.HiveClient;
 import org.apache.hadoop.hive.service.HiveInterface;
 import org.apache.hadoop.hive.service.HiveServer;
+import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TBinaryProtocol;
 import org.apache.thrift.protocol.TProtocol;
 import org.apache.thrift.transport.TSocket;
@@ -126,12 +127,17 @@
public void clearWarnings() throws SQLException {
    */
 
   public void close() throws SQLException {
-    try {
-      if (transport != null) {
-        transport.close();
+    if (!isClosed) {
+      try {
+        client.clean();
+      } catch (TException e) {
+        throw new SQLException("Error while cleaning up the server resources", e);
+      } finally {
+        isClosed = true;
+        if (transport != null) {
+          transport.close();
+        }
       }
-    } finally {
-      isClosed = true;
     }
   }
 
